package bTree.LeetCode;

public class 整数替换 {
    public int integerReplacement(int n) {
        return recurrence(n);
    }

    private int recurrence(long n) {
        if (n==1){
            return 0;
        }
        if (n%2==1){
            return 1+Math.min(recurrence(n-1),recurrence(n+1));
        }else {
            return 1+recurrence(n/2);
        }
    }
}